x86/MSI-X: restrict reading of table/PBA bases from BARs
authorJan Beulich <jbeulich@suse.com>
Tue, 22 Sep 2020 14:11:38 +0000 (16:11 +0200)
committerJan Beulich <jbeulich@suse.com>
Tue, 22 Sep 2020 14:11:38 +0000 (16:11 +0200)
commit0bc4177e6b0d7a98464913af95d3bfe4b59b7a2c
tree10a4b95d90cb36d72823b0cfff4928ec74d5c6a1
parent5ad31525c9aeed6d3a349799fe491b5a7c678049
x86/MSI-X: restrict reading of table/PBA bases from BARs

When assigned to less trusted or un-trusted guests, devices may change
state behind our backs (they may e.g. get reset by means we may not know
about). Therefore we should avoid reading BARs from hardware once a
device is no longer owned by Dom0. Furthermore when we can't read a BAR,
or when we read zero, we shouldn't instead use the caller provided
address unless that caller can be trusted.

Re-arrange the logic in msix_capability_init() such that only Dom0 (and
only if the device isn't DomU-owned yet) or calls through
PHYSDEVOP_prepare_msix will actually result in the reading of the
respective BAR register(s). Additionally do so only as long as in-use
table entries are known (note that invocation of PHYSDEVOP_prepare_msix
counts as a "pseudo" entry). In all other uses the value already
recorded will get used instead.

Clear the recorded values in _pci_cleanup_msix() as well as on the one
affected error path. (Adjust this error path to also avoid blindly
disabling MSI-X when it was enabled on entry to the function.)

While moving around variable declarations (in many cases to reduce their
scopes), also adjust some of their types.

This is part of XSA-337.

Signed-off-by: Jan Beulich <jbeulich@suse.com>
Reviewed-by: Roger Pau Monné <roger.pau@citrix.com>
xen/arch/x86/msi.c